﻿using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Windows.Controls;
using WpfApp1.Enum;
using WpfApp1.Model;
using WpfApp1.ViewModel;

namespace WpfApp1.View
{
    /// <summary>
    /// TrainDetail.xaml 的交互逻辑
    /// </summary>
    public partial class TrainDetail : UserControl
    {

        public TrainDetail()
        {
            InitializeComponent();
        }

        public void InitForm()
        {
            if (DataContext == null)
            {
                return;
            }

            TrainModel trainModel = DataContext as TrainModel;
            long id = trainModel.Id;
            string sql_data = "select * from train where id=" + id;
            SQLiteCommand command = new SQLiteCommand(sql_data, MainWindow.connecttion);
            SQLiteDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                trainModel.Require = reader["require"].ToString();
                trainModel.Effect = reader["effect"].ToString();
                trainModel.FeedBack = reader["feedback"].ToString();
                trainModel.Summary = reader["summary"].ToString();
                trainModel.PptName = reader["ppt_path"].ToString();
            }

            DataContext = trainModel;
            Console.WriteLine("{0}", trainModel.StartTime);
        }

        private void Submit(object sender, System.Windows.RoutedEventArgs e)
        {
            long id = Convert.ToInt64(id_first.Text);
            long parentId = Convert.ToInt64(id_main.Text);
            TrainSubject subjectOne = (TrainSubject)(Convert.ToInt64(subject.Text));
            if (DataContext == null)
            {
                return;
            }

            TrainModel train = DataContext as TrainModel;
            if (train.Id <= 0)
            {
                string sql = "insert into ";
            }
        }

        private void Kindsbox_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Console.WriteLine("{0}",e.OriginalSource);
        }

        // 鼠标滑过更新品种box框
        private void Kindsbox_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            TrainModel trainModel = DataContext as TrainModel;
            List<ProductKind> productKinds = trainModel.Kinds;
            string kind = "";
            foreach(ProductKind productKind in productKinds)
            {
                kind += "," + productKind;
            }
            trainModel.Kind = kind.TrimStart(",".ToCharArray());
        }

        private void Start_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<object> e)
        {
            Console.WriteLine("{0}");
        }

        private void Start_TextChanged(object sender, TextChangedEventArgs e)
        {
        }
    }
}
